﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
using Data;
namespace DAO
{
    public class KhachHang_DAO
    {
        public static List<KhachHang_DTO> SelectAll()
        {
            List<KhachHang_DTO> result = new List<KhachHang_DTO>();
            DataTable dt = Data.SQLAccess.ExecuteQuery("select *from KHACH_HANG");
            DTO.KhachHang_DTO khach_hang;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                khach_hang = new DTO.KhachHang_DTO();
                khach_hang._Ma_KH = int.Parse(dt.Rows[i]["MA_KH"].ToString());
                khach_hang._CMND = dt.Rows[i]["CMND"].ToString();
                khach_hang._Ten = dt.Rows[i]["TEN_KH"].ToString();
                khach_hang._Dia_Chi = dt.Rows[i]["DIA_CHI"].ToString();
                khach_hang._Dien_Thoai = dt.Rows[i]["DIEN_THOAI"].ToString();
                khach_hang._Diem_Tich_Luy = int.Parse(dt.Rows[i]["DIEM_TICH_LUY"].ToString());
                khach_hang._Ma_Loai_KH = int.Parse(dt.Rows[i]["MA_LOAI_KH"].ToString());
                result.Add(khach_hang);
            }
            return result;
        }
        public static string Insert(KhachHang_DTO khach_hang)
        {
            try
            {
                string str_sql = "insert into KHACH_HANG values("
                + khach_hang._Ma_KH + ",'" 
                + khach_hang._CMND + "','"
                + khach_hang._Ten + "','N"
                + khach_hang._Dia_Chi + "','"
                + khach_hang._Dien_Thoai + "',"
                + khach_hang._Diem_Tich_Luy + ","
                + khach_hang._Ma_Loai_KH + ""
                + ")";
                DataTable dt = Data.SQLAccess.ExecuteQuery(str_sql);
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        public static string Delete(KhachHang_DTO khach_hang)
        {
            try
            {
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}
